﻿'Description:看板数据导入类
'Copyright (c) : 通力凯顿（北京）系统集成有限公司
'Writer:YangJiang
'create Date:2018-3-14
'Rewriter:
'Rewrite Date:
Imports BusinessRule.IBusiness
Imports DatabaseAccess.DBUtility
Imports System.Text

Public Class uLMSLookBoardDataImportBusiness
    Implements uLMSLookBoardDataImportIBusiness

    ''' <summary>
    ''' 查询出勤率信息
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetAttendanceRate(ByVal maxAttendancerateDate As String, ByVal minAttendancerateDate As String) As System.Data.DataTable Implements IBusiness.uLMSLookBoardDataImportIBusiness.GetAttendanceRate
        Dim strSQL As String = "SELECT * FROM ATTENDANCERATE WHERE AttendancerateDate>=to_date('" & minAttendancerateDate & "','yyyy/mm/dd') AND AttendancerateDate<=to_date('" & maxAttendancerateDate & "','yyyy/mm/dd')"
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(strSQL)
        If dt Is Nothing Then
            GetAttendanceRate = New DataTable
        Else
            GetAttendanceRate = dt
        End If
    End Function
    ''' <summary>
    ''' 查询经济运行指标
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetEconomicIndex(ByVal maxEconomicYear As String, ByVal minEconomicYear As String, ByVal maxEconomicMonth As String, ByVal minEconomicMonth As String) As System.Data.DataTable Implements IBusiness.uLMSLookBoardDataImportIBusiness.GetEconomicIndex
        Dim strSQL As New StringBuilder
        strSQL.AppendLine("SELECT * FROM ECONOMICINDEX")
        strSQL.AppendLine("WHERE EconomicYear>='" & minEconomicYear & "' AND EconomicYear<='" & maxEconomicYear & "'")
        strSQL.AppendLine("AND EconomicMonth>='" & minEconomicMonth & "' AND EconomicMonth<='" & maxEconomicMonth & "'")

        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(strSQL.ToString)
        If dt Is Nothing Then
            GetEconomicIndex = New DataTable
        Else
            GetEconomicIndex = dt
        End If
    End Function
    ''' <summary>
    ''' 查询月度计划
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetProductFamilyMonthPlan(ByVal maxPlanMonth As String, ByVal minPlanMonth As String) As System.Data.DataTable Implements IBusiness.uLMSLookBoardDataImportIBusiness.GetProductFamilyMonthPlan
        Dim strSQL As String = "SELECT * FROM PRODUCTFAMILYMONTHPLAN WHERE PlanMonth>='" & minPlanMonth & "' AND PlanMonth<='" & maxPlanMonth & "'"
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(strSQL)
        If dt Is Nothing Then
            GetProductFamilyMonthPlan = New DataTable
        Else
            GetProductFamilyMonthPlan = dt
        End If
    End Function
    ''' <summary>
    ''' 查询单台信息
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetProductFamilySingleInfo(ByVal ProductFamilyType As String) As System.Data.DataTable Implements IBusiness.uLMSLookBoardDataImportIBusiness.GetProductFamilySingleInfo
        Dim strSQL As String = "SELECT * FROM PRODUCTFAMILYSINGLEINFO WHERE ProductFamilyType =" & ProductFamilyType & ""
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(strSQL)
        If dt Is Nothing Then
            GetProductFamilySingleInfo = New DataTable
        Else
            GetProductFamilySingleInfo = dt
        End If
    End Function
    ''' <summary>
    ''' 查询设备利用率
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function GetResourceUseRate(ByVal maxResourcerateYear As String, ByVal minResourcerateYear As String, ByVal maxResourcerateMonth As String, ByVal minResourcerateMonth As String) As System.Data.DataTable Implements IBusiness.uLMSLookBoardDataImportIBusiness.GetResourceUseRate
        Dim strSQL As New StringBuilder
        strSQL.AppendLine("SELECT * FROM RESOURCEUSERATE")
        strSQL.AppendLine("WHERE ResourcerateYear>='" & minResourcerateYear & "' AND ResourcerateYear<='" & maxResourcerateYear & "'")
        strSQL.AppendLine("AND ResourcerateMonth>='" & minResourcerateMonth & "' AND ResourcerateMonth<='" & maxResourcerateMonth & "'")
        Dim dt As DataTable = DatabaseHelper.Query_ReturnDatTable(strSQL.ToString)
        If dt Is Nothing Then
            GetResourceUseRate = New DataTable
        Else
            GetResourceUseRate = dt
        End If
    End Function

    ''' <summary>
    ''' 根据时间删除出勤率数据
    ''' </summary>
    ''' <param name="maxAttendancerateDate"></param>
    ''' <param name="minAttendancerateDate"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteAttendanceRateByDate(ByVal maxAttendancerateDate As String, ByVal minAttendancerateDate As String) As Boolean Implements IBusiness.uLMSLookBoardDataImportIBusiness.DeleteAttendanceRateByDate
        Dim strSQL As New StringBuilder
        strSQL.AppendLine(" DELETE AttendanceRate ")
        strSQL.AppendLine(" WHERE AttendancerateDate>=to_date('" & minAttendancerateDate & "','yyyy/mm/dd') AND AttendancerateDate<=to_date('" & maxAttendancerateDate & "','yyyy/mm/dd')")
        If (DatabaseHelper.ExecuteSql(strSQL.ToString) > 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 根据时间删除经济运行指标数据
    ''' </summary>
    ''' <param name="minEconomicYear"></param>
    ''' <param name="minEconomicMonth"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteEconomicIndexByDate(ByVal minEconomicYear As String, ByVal minEconomicMonth As String) As Boolean Implements IBusiness.uLMSLookBoardDataImportIBusiness.DeleteEconomicIndexByDate
        Dim strSQL As New StringBuilder
        strSQL.AppendLine(" DELETE EconomicIndex ")
        strSQL.AppendLine("WHERE EconomicYear='" & minEconomicYear & "' AND EconomicMonth='" & minEconomicMonth & "'")
        If (DatabaseHelper.ExecuteSql(strSQL.ToString) > 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 根据时间删除月度计划数据
    ''' </summary>
    ''' <param name="minPlanMonth"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteProductFamilyMonthPlanByDate(ByVal minPlanMonth As String) As Boolean Implements IBusiness.uLMSLookBoardDataImportIBusiness.DeleteProductFamilyMonthPlanByDate
        Dim strSQL As New StringBuilder
        strSQL.AppendLine(" DELETE ProductFamilyMonthPlan WHERE PlanMonth='" & minPlanMonth & "' ")
        If (DatabaseHelper.ExecuteSql(strSQL.ToString) > 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 根据类型删除单台信息数据
    ''' </summary>
    ''' <param name="ProductFamilyType"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteProductFamilySingleInfoByDate(ByVal ProductFamilyType As String) As Boolean Implements IBusiness.uLMSLookBoardDataImportIBusiness.DeleteProductFamilySingleInfoByDate
        Dim strSQL As New StringBuilder
        strSQL.AppendLine(" DELETE ProductFamilySingleInfo WHERE ProductFamilyType='" & ProductFamilyType & "' ")
        If (DatabaseHelper.ExecuteSql(strSQL.ToString) > 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 根据时间删除设备利用率数据
    ''' </summary>
    ''' <param name="minResourcerateYear"></param>
    ''' <param name="minResourcerateMonth"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteResourceUseRateByDate(ByVal minResourcerateYear As String, ByVal minResourcerateMonth As String) As Boolean Implements IBusiness.uLMSLookBoardDataImportIBusiness.DeleteResourceUseRateByDate
        Dim strSQL As New StringBuilder
        strSQL.AppendLine(" DELETE ResourceUseRate ")
        strSQL.AppendLine("WHERE ResourcerateYear='" & minResourcerateYear & "' AND ResourcerateMonth='" & minResourcerateMonth & "'")
        If (DatabaseHelper.ExecuteSql(strSQL.ToString) > 0) Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 删除热表计划数据
    ''' </summary>
    ''' <param name="para"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function DeleteProductFamilyConsistInfo(ByVal para As Dictionary(Of String, Object)) As Boolean Implements IBusiness.uLMSLookBoardDataImportIBusiness.DeleteProductFamilyConsistInfo
        Dim sb As StringBuilder = New StringBuilder()
        sb.AppendFormat("DELETE productfamilyconsistinfo t WHERE t.productfamily='{0}' AND t.productname='{1}' AND t.planfinishdate = to_date('{2}','yyyy/mm/dd') AND t.priorityno = '{3}'",
                        para("ProductFamily"), para("ProductName"), para("PlanFinishDate"), para("PriorityNo"))
        DatabaseHelper.ExecuteSql(sb.ToString)
        Return True
    End Function
End Class
